package com.wealth.system.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 用户
 * @author chan
 */

@Entity
@Table(name = "system_user")
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String username;
	private String password;
	private String plainPassword;	//输入新密码
	private Corporation corp;
	private Date createtime;
	private String creator;
	private Integer status;
	
	private List<Role> roleList = new ArrayList<Role>(); 		//用户-角色
	
	/* ---------------- method ----------------*/
	
	public User() {}
	
	public User(Long id){
		this.id = id;
	}
	
	public User(String username,String password){
		this.username = username;
		this.password = password;
	}

	/* ---------------- getter/setter ---------------- */
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@ManyToMany
	@JoinTable(name = "system_user_role", 
		joinColumns = { @JoinColumn(name = "user_id") },
		inverseJoinColumns = { @JoinColumn(name = "role_id") }
	)
	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}
	
	@ManyToOne  
    @JoinColumn(name="corp_id")
	public Corporation getCorp() {
		return corp;
	}

	public void setCorp(Corporation corp) {
		this.corp = corp;
	}

//	@OneToOne (cascade=CascadeType.ALL) 
//    @JoinColumn(name="userinfo_id")
//	public UserInfo getUserinfo() {
//		return userinfo;
//	}
//	
//	public void setUserinfo(UserInfo userinfo) {
//		this.userinfo = userinfo;
//	}
	
	@Transient
	public String getPlainPassword() {
		return plainPassword;
	}

	public void setPlainPassword(String plainPassword) {
		this.plainPassword = plainPassword;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@Column(name="create_time")
	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
}
